home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Demos / RainingBobs.s < prev    next >
Encoding:
Text File  |  1997-07-08  |  7.6 KB  |  319 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Name:      Raining Bob's Demo
  3. ;Author:    Paul Manias
  4. ;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
  5. ;
  6. ;This is a demonstration of raining bobs, which I use as a test routine to
  7. ;see how fast some of my blitter routines are.  It's a good example of using
  8. ;MBOB's, try out different MAX_IMAGES values to see how many you can get on
  9. ;screen.  **120** 16 colour 16x8 bobs just manage to run at full speed on my
  10. ;A1200+FAST, change the value if you have a faster machine (600 can be very
  11. ;interesting :-).
  12. ;
  13. ;Technical notes
  14. ;---------------
  15. ;This demo takes direct advantage of some special GMS blitting features,
  16. ;such as restorelist clearing without masks (gain: 10%), and 16 pixel
  17. ;alignment (gain: 15%).  That allows us to have 25% more BOB's on screen!
  18. ;
  19. ;The fact that GMS will use the CPU to draw and clear images when the blitter
  20. ;is busy gives a boost of about 20%+ on an '020, so the overall advantage
  21. ;over a bog standard blitting function (eg BltBitmap()) is at least 40%.
  22. ;Given that such a function would have to be called 120 times with newly
  23. ;calculated parameters each time to draw, and 120 times to do the clears, we
  24. ;are probably looking at least 65% faster... is that good enough?
  25.  
  26.     INCDIR    "INCLUDES:"
  27.     INCLUDE    "games/games_lib.i"
  28.     INCLUDE    "games/games.i"
  29.  
  30. MAX_IMAGES =    120
  31.  
  32.     SECTION    "RainingBOBs",CODE
  33.  
  34. ;===========================================================================;
  35. ;                             INITIALISE DEMO
  36. ;===========================================================================;
  37.  
  38.     STARTGMS
  39.  
  40. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  41.     move.l    GMSBase(pc),a6
  42.     CALL    AllocBlitter
  43.     tst.l    d0
  44.     bne    .Error_Blitter
  45.  
  46.     lea    TAGS_BobsPicture(pc),a1
  47.     CALL    LoadPic
  48.     tst.l    d0
  49.     beq.s    .Error_Picture
  50.  
  51.     move.l    PIC_Bobs(pc),a1
  52.     move.w    PIC_Planes(a1),GPlanes+2
  53.     move.l    PIC_Palette(a1),GPalette
  54.  
  55.     lea    TAGS_Screen(pc),a0
  56.     CALL    AddScreen
  57.     move.l    d0,Screen
  58.     beq.s    .Error_Screen
  59.  
  60.     move.l    Screen(pc),a0
  61.     move.l    #MAX_IMAGES,d1    ;d1 = Maximum amount of images.
  62.     CALL    InitRestore
  63.     tst.l    d0
  64.     beq.s    .Error_Restorelist
  65.  
  66.     move.l    Screen(pc),a0
  67.     move.l    GS_Bitmap(a0),a0
  68.     lea    TAGS_RainBob(pc),a1
  69.     CALL    InitBob    ;>> = Initialise the Bob.
  70.     tst.l    d0
  71.     beq.s    .Error_RainBob
  72.  
  73.     move.l    Screen(pc),a0
  74.     CALL    ShowScreen
  75.  
  76.     CALL    InitJoyPorts
  77.  
  78.     bsr.s    Main
  79.  
  80. .ReturnToDOS
  81.     move.l    GMSBase(pc),a6
  82.     move.l    MBOB_Rain(pc),a1
  83.     CALL    FreeBob
  84. .Error_RainBob
  85.     move.l    Screen(pc),a0
  86.     CALL    FreeRestore
  87. .Error_Restorelist
  88.     move.l    Screen(pc),a0
  89.     CALL    DeleteScreen
  90. .Error_Screen
  91.     move.l    PIC_Bobs(pc),a1
  92.     CALL    FreePic
  93. .Error_Picture
  94.     CALL    FreeBlitter
  95. .Error_Blitter
  96.     MOVEM.L    (SP)+,A0-A6/D1-D7
  97.     moveq    #ERR_OK,d0
  98.     rts
  99.  
  100. ;===========================================================================;
  101. ;                                DEMO CODE
  102. ;===========================================================================;
  103.  
  104. Main:    moveq    #$00,d7
  105.     move.l    MBOB_Rain(pc),a1
  106.  
  107.     move.l    Screen(pc),a0    ;a0 = GameScreen.
  108.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  109.     move.w    MB_AmtEntries(a1),d2
  110.     subq.w    #1,d2
  111. .create    bsr    RegenerateBob
  112.  
  113.     move.w    GS_ScrHeight(a0),d1
  114.     CALL    FastRandom
  115.     move.w    d0,BE_YCoord(a2)
  116.  
  117.     lea    NBE_SIZEOF(a2),a2
  118.     dbra    d2,.create
  119.  
  120. ;---------------------------------------------------------------------------;
  121.  
  122. Loop:    addq.w    #1,d7
  123.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  124.     move.w    MB_AmtEntries(a1),d2
  125.     subq.w    #1,d2
  126. .update    bsr.s    UpdateBob
  127.     lea    NBE_SIZEOF(a2),a2
  128.     dbra    d2,.update
  129.  
  130.     move.l    Screen(pc),a0
  131.     move.l    GS_Bitmap(a0),a0
  132.     CALL    Restore
  133.  
  134.     move.l    MBOB_Rain(pc),a1    ;a1 = Bob to draw.
  135.     CALL    DrawBob    ;>> = Draw the mbob.
  136.  
  137.     CALL    WaitVBL    ;>> = Wait for VBL.
  138.  
  139.     move.l    Screen(pc),a0
  140.     CALL    SwapBuffers    ;>> = Swap the buffers.
  141.  
  142.     moveq    #JPORT1,d0    ;d0 = JoyPort2
  143.     moveq    #JT_ZBXY,d1    ;d1 = Bit switch type.
  144.     CALL    ReadJoyPort    ;>> = Go get port status.
  145.     btst    #MB_LMB,d0
  146.     beq.s    Loop
  147.     rts
  148.  
  149. ;===========================================================================;
  150. ;                               UPDATE A BOB
  151. ;===========================================================================;
  152. ;Function: Moves the entity according to its internal settings.
  153. ;Requires: a1 = Bob structure.
  154. ;       a2 = Entry to update.
  155.  
  156. UpdateBob:
  157.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  158.     add.w    BE_Speed(a2),d0    ;d0 = (YCoord)+YSpeed
  159.     cmp.w    GS_ScrHeight(a0),d0
  160.     blt.s    .YOkay
  161.     bsr    RegenerateBob
  162.     bra.s    .Animate
  163. .YOkay    move.w    d0,BE_YCoord(a2)
  164.  
  165. .Animate
  166.     tst.w    BE_Locked(a2)
  167.     beq.s    .exit
  168.     move.w    d7,d6
  169.     and.w    #%00000011,d6
  170.     bne.s    .exit
  171.     move.w    BE_FChange(a2),d1
  172.     bgt.s    .Positive
  173.  
  174. .Negative
  175.     cmp.w    #1,BE_Set(a2)
  176.     bgt.s    .NBlue
  177.     beq.s    .NGreen
  178. .NRed    add.w    d1,BE_Frame(a2)
  179.     tst    BE_Frame(a2)
  180.     bge.s    .exit
  181.     move.w    #1,BE_FChange(a2)
  182.     clr.w    BE_Frame(a2)
  183.     rts
  184. .NGreen    add.w    d1,BE_Frame(a2)
  185.     cmp.w    #4,BE_Frame(a2)
  186.     bge.s    .done
  187.     move.w    #1,BE_FChange(a2)
  188.     move.w    #4,BE_Frame(a2)
  189.     rts
  190. .NBlue    add.w    d1,BE_Frame(a2)
  191.     cmp.w    #8,BE_Frame(a2)
  192.     bge.s    .done
  193.     move.w    #1,BE_FChange(a2)
  194.     move.w    #8,BE_Frame(a2)
  195. .exit    rts
  196.  
  197. .Positive
  198.     cmp.w    #1,BE_Set(a2)
  199.     bgt.s    .PBlue
  200.     beq.s    .PGreen
  201. .PRed    add.w    d1,BE_Frame(a2)
  202.     cmp.w    #3,BE_Frame(a2)
  203.     ble.s    .done
  204.     move.w    #-1,BE_FChange(a2)
  205.     move.w    #2,BE_Frame(a2)
  206.     rts
  207. .PGreen    add.w    d1,BE_Frame(a2)
  208.     cmp.w    #7,BE_Frame(a2)
  209.     ble.s    .done
  210.     move.w    #-1,BE_FChange(a2)
  211.     move.w    #6,BE_Frame(a2)
  212.     rts
  213. .PBlue    add.w    d1,BE_Frame(a2)
  214.     cmp.w    #11,BE_Frame(a2)
  215.     ble.s    .done
  216.     move.w    #-1,BE_FChange(a2)
  217.     move.w    #10,BE_Frame(a2)
  218. .done    rts
  219.  
  220. ;===========================================================================;
  221. ;                            REGENERATE BOB ENTITY
  222. ;===========================================================================;
  223. ;Function: Regenerates an entity with completely new data.
  224. ;Requires: a2 = Entry to update.
  225.  
  226. RegenerateBob:
  227.     move.w    GS_ScrWidth(a0),d1
  228.     CALL    FastRandom
  229.     subq.w    #4,d0
  230.     and.w    #%1111111111111000,d0
  231.     move.w    d0,BE_XCoord(a2)
  232.  
  233.     moveq    #8,d1
  234.     CALL    FastRandom
  235.     addq.w    #2,d0
  236.     move.w    d0,BE_Speed(a2)
  237.  
  238.     moveq    #12,d1
  239.     CALL    FastRandom
  240.     move.w    d0,BE_Frame(a2)
  241.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  242.  
  243.     move.w    #-8,BE_YCoord(a2)
  244.     move.w    #1,BE_FChange(a2)
  245.     eor.w    #1,BE_Locked(a2)
  246.     rts
  247.  
  248. .Sets    dc.b    0,0,0,0
  249.     dc.b    1,1,1,1
  250.     dc.b    2,2,2,2
  251.  
  252. ;===========================================================================;
  253. ;                                  DATA
  254. ;===========================================================================;
  255.  
  256. TAGS_Screen:    dc.l  TAGS_GAMESCREEN
  257. Screen:        dc.l  0
  258.         dc.l  GSA_Palette
  259. GPalette:    dc.l  0
  260.         dc.l  GSA_Planes
  261. GPlanes:    dc.l  0
  262.         dc.l  GSA_Attrib,DBLBUFFER
  263.         dc.l  TAGEND
  264.  
  265. ;---------------------------------------------------------------------------;
  266.  
  267. TAGS_BobsPicture:
  268.         dc.l  TAGS_PICTURE
  269. PIC_Bobs:    dc.l  0
  270.         dc.l  PCA_Options,VIDEOMEM|GETPALETTE
  271.         dc.l  PCA_File,.file
  272.         dc.l  TAGEND
  273. .file        dc.b  "GMS:demos/data/PIC.Pulse",0
  274.         even
  275.  
  276. ;---------------------------------------------------------------------------;
  277.  
  278.   ;This is a mutated entrylist that we use for the raining bobs.
  279.  
  280.   STRUCTURE    NBE,BE_SIZEOF
  281.     WORD    BE_Speed    ;Speed of this particular bob.
  282.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  283.     WORD    BE_FChange
  284.     WORD    BE_Locked    ;Is it animated or not.
  285.     LABEL    NBE_SIZEOF
  286.  
  287. TAGS_RainBob:    dc.l  TAGS_MBOB
  288. MBOB_Rain:    dc.l  0
  289.         dc.l  MBA_AmtEntries,MAX_IMAGES
  290.         dc.l  MBA_GfxCoords,.frames
  291.         dc.l  MBA_Width,8
  292.         dc.l  MBA_Height,8
  293.         dc.l  MBA_EntryList,Images
  294.         dc.l  MBA_Attrib,CLIP|GENMASKS|CLEAR|CLRNOMASK
  295.         dc.l  MBA_PictureTags,TAGS_BobsPicture
  296.         dc.l  MBA_EntrySize,NBE_SIZEOF
  297.         dc.l  TAGEND
  298.  
  299. .frames        dc.w   0,8*0    ;RED
  300.         dc.w   0,8*1
  301.         dc.w   0,8*2
  302.         dc.w   0,8*3
  303.         dc.w   8,8*0    ;GREEN
  304.         dc.w   8,8*1
  305.         dc.w   8,8*2
  306.         dc.w   8,8*3
  307.         dc.w  16,8*0    ;BLUE
  308.         dc.w  16,8*1
  309.         dc.w  16,8*2
  310.         dc.w  16,8*3
  311.         dc.l  -1
  312.  
  313. ;---------------------------------------------------------------------------;
  314.  
  315.     SECTION    Images,BSS
  316.  
  317. Images:    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  318.  
  319.